﻿using System;
namespace IFramework
{
    public partial class RefectFactory
    {
        public static object CreateInstance(Type type, Action action)
        {
            object obj = Activator.CreateInstance(type);
            if (action != null)
            {
                action.Invoke();
            }
            return obj;
        }
        public static object CreateInstance(Type type, bool nonPublic, Action action)
        {
            object obj = Activator.CreateInstance(type, nonPublic);
            if (action != null)
            {
                action.Invoke();
            }
            return obj;
        }
        public static object CreateInstance(Type type, Action action, params object[] args)
        {
            object obj = Activator.CreateInstance(type, args);
            if (action != null)
            {
                action.Invoke();
            }
            return obj;
        }
        public static object CreateInstance(Type type, Action action, object[] args, object[] activationAttributes)
        {
            object obj = Activator.CreateInstance(type, args, activationAttributes);
            if (action != null)
            {
                action.Invoke();
            }
            return obj;
        }
        public static T CreateInstance<T>(Action action)
        {
            T obj = Activator.CreateInstance<T>();
            if (action != null)
            {
                action.Invoke();
            }
            return obj;
        }

    }
}
